package ph.com.gs3.formalistics.notification.receiver.utilities;

import java.io.PrintWriter;
import java.io.StringWriter;

import android.util.Log;

public class FLLogger {

	public static final String TAG = FLLogger.class.getSimpleName();

	public static final int MODE_DEVELOPMENT = 0;
	public static final int MODE_PRODUCTION = 1;

	private static int mode = MODE_PRODUCTION;

	public static enum LogType {
		ERROR, WARNING, MESSAGE, DEBUG
	}

	public static final void log(LogType logType, String log) {
		Log.v(TAG, log);
	}

	public static final void log(String source, LogType logType, String log) {

		switch (logType) {
			case ERROR:
				Log.e(source, log);
				break;
			case WARNING:
				Log.w(source, log);
				break;
			case MESSAGE:
				Log.v(source, log);
				break;
			case DEBUG: {
				if (mode == MODE_DEVELOPMENT) {
					Log.v(source, log);
				}
			}

				break;
		}

	}

	// =========================================================================
	// Other utility methods

	public static final String getStringStackTrace(Throwable exception) {

		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		exception.printStackTrace(pw);
		return sw.toString();

	}

	// =========================================================================
	// Shortcut methods

	public static final void m(String source, String log) {
		log(source, LogType.MESSAGE, log);
	}

	public static final void w(String source, String log) {
		log(source, LogType.WARNING, log);
	}

	public static final void e(String source, String log) {
		log(source, LogType.ERROR, log);
	}

	public static final void d(String source, String log) {
		log(source, LogType.DEBUG, log);
	}

	// =========================================================================
	// Getters & Setters

	public static void setMode(int mode) {
		FLLogger.mode = mode;
	}

	public static int getMode() {
		return FLLogger.mode;
	}

}
